package com.sparrow.socket.tcp.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 服务器状态处理器
 */
public class ServerStateHandler extends ChannelInboundHandlerAdapter {
    private static Logger logger = LoggerFactory.getLogger(ServerStateHandler.class);

    private static volatile boolean open = true;

    public static void setOpen(boolean isOpen) {
        open = isOpen;
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        if (!open) {
            // 关服状态
            ctx.close();
            logger.error("服务器正在维护中 无法连接{}", ctx);
            return;
        }
        super.channelActive(ctx);
    }
}
